# 默认目标
.PHONY: build run test clean deps

# 应用名称
APP_NAME := toolset
ENCRYPTION_TOOL := encryption-tool

# Go参数
GO := go
GO_BUILD := $(GO) build
GO_CLEAN := $(GO) clean
GO_TEST := $(GO) test
GO_GET := $(GO) get

# 构建目录
BUILD_DIR := build
MAIN_DIR := cmd/toolset
ENCRYPTION_TOOL_DIR := cmd/encryption-tool

# 构建应用
build: clean
	@echo "Building $(APP_NAME)..."
	@mkdir -p $(BUILD_DIR)
	$(GO_BUILD) -o $(BUILD_DIR)/$(APP_NAME) ./$(MAIN_DIR)
	@echo "Building $(ENCRYPTION_TOOL)..."
	$(GO_BUILD) -o $(BUILD_DIR)/$(ENCRYPTION_TOOL) ./$(ENCRYPTION_TOOL_DIR)
	@echo "Build completed successfully!"

# 运行应用
run: build
	@echo "Starting $(APP_NAME)..."
	@./$(BUILD_DIR)/$(APP_NAME)

# 安装依赖
deps:
	@echo "Installing dependencies..."
	$(GO_GET) -v ./...

# 测试
test:
	@echo "Running tests..."
	$(GO_TEST) -v ./...

# 清理构建产物
clean:
	@echo "Cleaning build artifacts..."
	@rm -rf $(BUILD_DIR)

# 帮助信息
help:
	@echo "Usage: make [target]"
	@echo
	@echo "Targets:"
	@echo "  build     Build the application"
	@echo "  run       Build and run the application"
	@echo "  deps      Install dependencies"
	@echo "  test      Run tests"
	@echo "  clean     Clean build artifacts"
	@echo "  help      Show this help message"